package com.spzx.test.t10;

import lombok.SneakyThrows;

public class Printer {

    Integer flag = 0;

    @SneakyThrows
    public synchronized void print0(){
        while(flag == 0){
            this.wait();
        }
        flag--;
        System.out.println(Thread.currentThread().getName()+"打印"+flag);
        this.notify();// 交互
    }

    @SneakyThrows
    public synchronized void print1(){
        while(flag == 1){
            this.wait();
        }
        flag++;
        System.out.println(Thread.currentThread().getName()+"打印"+flag);
        this.notify();// 交互
    }

}
